/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ChatNI;

import common.*;
import java.io.File;
import java.net.InetAddress;

/**
 * FabriqueFile
 * Class specific for building the messages corresponds with a file transfer
 * @author Duy Duc , Metangmo 
 */

public class FabriqueFile {
    
    /**
     * creerFile:
     * functions builds the different types of message concern a file transfer
     * @param type
     *        Type of the built message ( TRANSFERTFILEACCEPT, TRANSFERTFILEREQUEST, FICHIER )
     * @param addr
     *        IP Address of the recipient
     * @param tailleFic
     *        Size of the file (in bytes )
     * @param fic
     *        Pointer to the file
     * @param acc
     *        True/False signifies the accept/the deny of the TRANSFERTFILEACCEPT message
     * @param nomFic
     *        Name of the file
     * @return
     *        Built message
     */
    public Message creerFile(FabriqueFile.TypeMessage type, InetAddress addr, int tailleFic, File fic, Boolean acc,String nomFic){
        Message mess = null;
        
        //Create different types of message
        switch(type)
        {
            
            case TRANSFERTFILEACCEPT: mess = new TransfertFileAccept(addr,acc);break;
            case TRANSFERTFILEREQUEST: mess = new TransfertFileRequest(addr,nomFic,tailleFic);break;
            case FICHIER: mess = new Fichier(addr,fic);break; 
        }
        return mess;
    }

    /**
     * TypeMessage
     * An enumeration identifies the different types of message that can be created by FabriqueFile
     */
    public enum TypeMessage {
       
        /**
         * Message is sent upon the recipient of a TRANSFERTFILEREQUEST message
         * The response can be positive (TRUE) or negative (FALSE)
         */
       
        TRANSFERTFILEACCEPT,
        
        /**
         * Message is sent when a demand of file transfer is activated
         */
        TRANSFERTFILEREQUEST,

        /**
         * Message is used by the ChatController for updating the Model
         * when having a file transfer
         */
        FICHIER,
        
    }
    
}